/*******matrix multiplicationm********************/

#include <iostream>
#include <stdlib.h>
#include <ctime>

using namespace std;

#define N 10
 
int main()
{
    int mat1[N][N],mat2[N][N],mat3[N][N];
    int mat1row,mat1col,mat2row,mat2col,mat3row,mat3col;
    cout<<"enter the size of the first matrix"<<endl;
    cin>>mat1row>>mat1col;
    cout<<"enter the size of the second matrix"<<endl;
    cin>>mat2row>>mat2col;
    if(mat1row!=mat2col||mat1col!=mat2row)
    {
        cout<<"error the size of matrix can't match"<<endl;
        return 0;
    }
    else
    {
        int seed=time(0);
        srand((unsigned int) seed);
        for(int i=0;i<mat1row;i++)
        {
            for(int j=0;j<mat1col;j++)
            {
                mat1[i][j]=rand()%10;
            }
        }

        cout<<"the first matrix is"<<endl;
         for(int i=0;i<mat1row;i++)
         {
             for(int j=0;j<mat1col;j++)
             {
                 cout<<mat1[i][j]<<"   ";
             }
             cout<<endl;
         }

         for(int i=0;i<mat2row;i++)
        {
            for(int j=0;j<mat2col;j++)
            {
                mat2[i][j]=rand()%10;
            }
        }

        cout<<"the second matrix is"<<endl;
         for(int i=0;i<mat2row;i++)
         {
             for(int j=0;j<mat2col;j++)
             {
                 cout<<mat2[i][j]<<"   ";
             }
             cout<<endl;
         }

         mat3row=mat1row;
         mat3col=mat2col;
         for(int i=0;i<mat3row;i++)
         {
             for(int j=0;j<mat3col;j++)
             {
                 mat3[i][j]=0;
                 for(int k=0;k<mat2row;k++)
                 {
                 mat3[i][j]+=mat1[i][k]*mat2[k][j];
                 }
             }
         }

         cout<<"the matrixs multiplication is"<<endl;
         for(int i=0;i<mat3row;i++)
         {
             for(int j=0;j<mat3col;j++)
             {
                 cout<<mat3[i][j]<<"   ";
             }
             cout<<endl;
         }
    }

    system("pause");
    return 0;
    
}
